#include "startup.h"
#include "uncategorized.h"

UINT8 MCU_memory[0x8000];
UINT16 MCU_bankaddresslist[0x10];
UINT8* buff_point; // 0x2F
UINT8* buff_point1; // 0x31
UINT8* Ram_Point1; // 0x38
UINT8* Ram_Point2; // 0x3A
UINT8* Write_buf; // 0x3C
UINT8* ReadBuf_Point; // 0x3E
UINT8* Read_buf; // 0x40

UINT8 ProgramSizeH = 0x72;
UINT8 ProgramSizeL = 0x00;
UINT8 MT_DataAddrL = 0x00;
UINT8 MT_DataAddrM = 0xD0;
UINT8 MT_DataAddrH = 0x7B;
UINT8 FontDataBaseAddr = 0x00;
UINT32 ChnInputDataAddr = 0x007BD000;
UINT8 Lcd_RamMapAddressMove = 0x01;
UINT16 Lcd_RamMapOldAddress = 0x0400;
UINT16 Lcd_RamMapNewAddress = 0x1000;

// SYSTEM_RESET 00000350 00000354
DWORD WINAPI startup(LPVOID lpThreadParameter)
{
	//MCU_memory[0x2A] = 0xD7;
	//MCU_memory[0x28] = 0xD7;
	//MCU_memory[0x2B] = 0x17;
	//MCU_memory[0x29] = 0x17;

	_SYSCON = 0x02;
	_CPUCLK = 0x03;
	_SYSCON = 0x44;
	_OSCK = 0xF3;
	_SYSCON = 0x05;

	_CPUCLK = 0x00;
	_0398:
	for (UINT8 x = 0x01; x < 0x05; x++)
	{
		MCU_bankaddresslist[x] = x;
	}
	_03AA:
	for (UINT8 x = 0x09; x < 0x0D; x++)
	{
		MCU_bankaddresslist[x] = 0x0E80 + (x - 0x09);
	}
	_03BE:
	for (UINT8 x = 0x0D; x < 0x10; x++)
	{
		MCU_bankaddresslist[x] = 0x0E88 + (x - 0x0D);
	}

	SysStart();

	return 0;
}
DWORD WINAPI startup_test(LPVOID lpThreadParameter)
{
	// init
	MCU_memory[0x2186] = 0x02;
	MCU_memory[0x219F] = 0x02;

	U16 filename;
	U8 filehandle;
	U8 information[0x0A] = "gamegame";
	FileCreat(0x3d, 0x010000, information, &filename, &filehandle);
	return 0;
}